<?php
namespace app\index\controller;

use aliyun\Sms;
use robot\Robot;
class Wuliu extends Common
{
	
	public function index()
	{
		$host = "https://courier.market.alicloudapi.com";

	    $path = "/courier";

	    $method = "GET";
	    $appcode = "ab7bfa4f7d544241998ea5d8a8ddb028";
	    $headers = array();
	    array_push($headers, "Authorization:APPCODE " . $appcode);
	    $querys = "com=圆通&no=803914608627928539";
	    $bodys = "";
	    $url = $host . $path . "?" . $querys;

	    $curl = curl_init();

	    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);

	    curl_setopt($curl, CURLOPT_URL, $url);
	    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
	    curl_setopt($curl, CURLOPT_FAILONERROR, false);
	    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
	    curl_setopt($curl, CURLOPT_HEADER, false);
	    if (1 == strpos("$".$host, "https://"))
	    {
	        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
	        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
	    }
	    var_dump(json_decode(curl_exec($curl),true));
	    var_dump(json_decode(curl_exec($curl),true)['result']['data']);
	}

	public function test2()
	{
		 $host = "https://wdexpress.market.alicloudapi.com";
	    $path = "/gxali";
	    $method = "GET";
	    $appcode = "ab7bfa4f7d544241998ea5d8a8ddb028";
	    $headers = array();
	    array_push($headers, "Authorization:APPCODE " . $appcode);
	    $querys = "n=803914608627928539&t=YTO";
	    $bodys = "";
	    $url = $host . $path . "?" . $querys;

	    $curl = curl_init();
	    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
	    curl_setopt($curl, CURLOPT_URL, $url);
	    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
	    curl_setopt($curl, CURLOPT_FAILONERROR, false);
	    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
	    curl_setopt($curl, CURLOPT_HEADER, false);
	    //curl_setopt($curl, CURLOPT_HEADER, true); 如不输出json, 请打开这行代码，打印调试头部状态码。
	    //状态码: 200 正常；400 URL无效；401 appCode错误； 403 次数用完； 500 API网管错误
	    if (1 == strpos("$".$host, "https://"))
	    {
	        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
	        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
	    }
	    $out_put = curl_exec($curl);
	    var_dump(json_decode($out_put,true));
	}

	public function tianqi($value='')
	{
		 $host = "https://saweather.market.alicloudapi.com";
	    $path = "/spot-to-weather";
	    $method = "GET";
	    $appcode = "ab7bfa4f7d544241998ea5d8a8ddb028";
	    $headers = array();
	    array_push($headers, "Authorization:APPCODE " . $appcode);
	    $querys = "area=广州";
	    $bodys = "";
	    $url = $host . $path . "?" . $querys;

	    $curl = curl_init();
	    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
	    curl_setopt($curl, CURLOPT_URL, $url);
	    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
	    curl_setopt($curl, CURLOPT_FAILONERROR, false);
	    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
	    curl_setopt($curl, CURLOPT_HEADER, false);
	    if (1 == strpos("$".$host, "https://"))
	    {
	        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
	        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
	    }
	    var_dump(curl_exec($curl));
	    var_dump(json_decode(curl_exec($curl),true));
	}

	public function fa()
	{
		$res = Sms::send('17713542387',mt_rand(1000,9999));

		var_dump($res);
	}

	public function msg()
	{
		$data = input('w');

		$res = Robot::send($data);

		var_dump($res);
	}

	 public function ip()
    {
    	$ip = "61.133.202.96";

    	$url= "http://ip.taobao.com/service/getIpInfo.php?ip=".$ip;


    	$curl = curl_init();

    	curl_setopt($curl,CURLOPT_URL,$url);

    	curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

    	$data = curl_exec($curl);


    	// $data = file_get_contents($url);

    	var_dump(json_decode($data,true));



    }
}